package controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpSession;

import entity.BookUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import service.BookUserService;


@Controller
public class BookUserController {

	@Autowired
	private BookUserService bookUserService;
	public void setBookUserService(BookUserService bookUserService) {
		this.bookUserService = bookUserService;
	}

	@RequestMapping("/login")
	public String login(String name, String password,
			HttpSession session, ModelMap attrs) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("name", name);
		map.put("password", password);
		BookUser user = bookUserService.findUser(map);
		if (user != null) {
			session.setAttribute("user", user);
			return "redirect:/list";
		} else {
			attrs.addAttribute("msg","用户名或者密码错误！");
			return "forward:/login.jsp";
		}

	}
}
